<template>
    <div class="btnItem" :class="[{ disabled: disabled }, type]" @click="$_click">
        <i :class="icon"></i>
        <span>{{ text }}</span>
    </div>
</template>

<script>
/**  
 * 按钮组件  
 * @property {String} prefix-class 自定义字体图标库前缀 - 默认cmd-icon  
 * @property {String} type 按钮类型
 * @property {String} text 按钮文本  
 */
export default {
    name: 'cmd-btn',

    props: {
        /**
         * 自定义字体图标库前缀
         */
        text: {
            type: String,
            default: '#按钮'
        },
        type: {
            type: String,
            default: 'common'
        },
        icon: {
            type: String,
            default: ''
        },
        disabled: {
            type: Boolean,
            default: false
        },
        prefixClass: {
            type: String,
            default: 'iconfont'
        },
        /**
         * 图标类型
         */
        /**
         * 图标颜色
         */
        color: {
            type: String,
            default: '#ffffff'
        },
        /**
         * 图标大小
         */
    },

    computed: {
        setStyle() {
            return `color: ${this.color};`
        }
    },

    methods: {
        $_click(e) {
            this.$emit('click', e)
        }
    }
}
</script>

<style lang="scss">
.btnItem {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    height: 30px;
    color: #ffffff;
    font-size: 12px;
    border-radius: 3px;

    &.common {
        background-color: #1a7bb9;

        &:hover {
            background-color: rgba($color: #1a7bb9, $alpha: 0.9);
        }

        &:active {
            background-color: rgba($color: #1a7bb9, $alpha: 0.8);
        }
    }

    &.edit {
        background-color: #1ab394;

        &.disabled {
            background-color: #1dc5a3;
            cursor: not-allowed;
        }
        
        &:hover {
            background-color: rgba($color: #1ab394, $alpha: 0.9);
        }

        &:active {
            background-color: rgba($color: #1ab394, $alpha: 0.8);
        }
    }

    &.delete {
        background-color: #ed5565;

        &.disabled {
            background-color: #ef6776;
            cursor: not-allowed;
        }
        
        &:hover {
            background-color: rgba($color: #ed5565, $alpha: 0.9);
        }

        &:active {
            background-color: rgba($color: #ed5565, $alpha: 0.8);
        }
    }

    &.expert {
        background-color: #f8ac59;

        &.disabled {
            background-color: #ca9965;
            cursor: not-allowed;
        }
        
        &:hover {
            background-color: rgba($color: #f8ac59, $alpha: 0.9);
        }

        &:active {
            background-color: rgba($color: #f8ac59, $alpha: 0.8);
        }
    }

    i {
        padding-right: 3px;
        font-size: 14px;
    }
}
</style>
